﻿using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PineLake.Drmwe.Tickets.RoleGroup
{
    /// <summary>
    /// 角色属性
    /// </summary>
    public class PineLakeAuthorizeAttribute : AuthorizeAttribute
    {
        private RoleGroupEnum RolesEnum;
        public RoleGroupEnum RoleEnum
        {
            get { return RolesEnum; }
            set { RolesEnum = value; base.Roles = SetRoleGroup(value.ToString()); }
        }
        /// <summary>
        /// 设置权限
        /// </summary>
        /// <param name="RoleGroupStr"></param>
        /// <returns></returns>
        private string SetRoleGroup(string RoleGroupStr)
        {
            var Roles = "";
            switch (RoleGroupStr)
            {
                case "RefreshToken":
                    Roles = RoleGroupEnum.RefreshToken.ToString();
                    break;
                case "External":
                    Roles = RoleGroupEnum.External.ToString();
                    break;
                case "General":
                    Roles = RoleGroupEnum.General.ToString() + "," + RoleGroupEnum.Manager.ToString() + "," + RoleGroupEnum.System.ToString();
                    break;
                case "Manager":
                    Roles = RoleGroupEnum.Manager.ToString() + "," + RoleGroupEnum.System.ToString();
                    break;
                case "System":
                    Roles = RoleGroupEnum.System.ToString();
                    break;
                default:
                    break;
            }
            return Roles;
        }
    }
}
